home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
docs
/
ippon
/
data
/
etc
/
round4.lzh
/
enemy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-04
|
6KB
|
357 lines
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <XSP2lib.H>
#include "boss01.h"
#include "enemy.h"
#include "fxsp2lib.h"
#define enemy_MAX 64 /* 最大数 */
#define P_OFFSET 8.0 /* 初期座標オフセット */
#define P_V0 0.2 /* 初速 */
#define P_A 0.5 /* 加速度 */
#define P_MAXV 1.5 /* 速度最大値 */
#define P_K 0.9 /* ばね定数 */
#define P_M 0.2 /* 摩擦計数 */
ENEMY *enemy, *enemy_top, *enemy_null_top;
extern char end_of_data;
int enemy_init0 (void)
{
int i;
if ((enemy = malloc (sizeof (enemy) * enemy_MAX)) == NULL)
return (-1);
enemy_top = NULL;
enemy_null_top = enemy;
for (i = 0; i < enemy_MAX; i++) {
enemy[i].next = &enemy[i + 1];
}
enemy[enemy_MAX - 1].next = NULL;
return (0);
}
void enemy_init (short type, short pt, short info, short ox, short oy)
{
if (enemy_null_top != NULL) {
ENEMY *p;
p = enemy_null_top;
enemy_null_top = p->next;
p->next = enemy_top;
enemy_top = p;
p->type = type;
p->pt = pt;
p->info = info;
p->ox = ox;
p->oy = oy;
switch (type) {
case 0: /* 本体 */
case 1:
case 2:
case 3:
break;
case 4: /* 可動部(左上) */
case 5:
case 6:
case 7:
p->lx = P_OFFSET;
p->ly = P_OFFSET;
p->vx = -P_V0;
p->vy = -P_V0;
p->cyc = 0;
break;
case 8: /* 可動部(右上) */
case 9:
case 10:
case 11:
p->lx = -P_OFFSET;
p->ly = P_OFFSET;
p->vx = P_V0;
p->vy = -P_V0;
p->cyc = 0;
break;
case 12: /* 可動部(左下) */
case 13:
case 14:
case 15:
p->lx = P_OFFSET;
p->ly = -P_OFFSET;
p->vx = -P_V0;
p->vy = P_V0;
p->cyc = 0;
break;
case 16: /* 可動部(右下) */
case 17:
case 18:
case 19:
p->lx = -P_OFFSET;
p->ly = -P_OFFSET;
p->vx = P_V0;
p->vy = P_V0;
p->cyc = 0;
break;
default:
break;
}
}
}
void enemy_move (void)
{
ENEMY *p, *q;
p = enemy_top;
q = NULL;
while (p != NULL) {
char erase_flag = 0;
switch (p->type) {
case 0: /* 本体 */
case 1:
case 2:
case 3:
p->x = p->ox;
p->y = p->oy;
p->x += (128 + 16); /* 表示用に補正 */
p->y += (128 + 16);
xsp_set_st (p);
fxsp_set_st (p);
p->x -= (128 + 16);
p->y -= (128 + 16);
break;
case 4: /* 可動部(左上) */
case 5:
case 6:
case 7:
switch (p->cyc) {
case 0:
p->vx -= P_A;
if (p->vx < -P_MAXV)
p->vx = -P_MAXV;
p->vy -= P_A;
if (p->vy < -P_MAXV)
p->vy = -P_MAXV;
if (p->lx < 0)
p->cyc++;
break;
case 1:
/* ばね運動 */
p->vx -= p->lx * P_K;
p->vy -= p->ly * P_K;
/* 摩擦 */
if (p->vx > 0)
p->vx -= P_M;
else
p->vx += P_M;
if (p->vy > 0)
p->vy -= P_M;
else
p->vy += P_M;
/* 終了判定 */
if ((fabs(p->vx)<0.5)&&((fabs(p->lx)<0.8)))
end_of_data = !0;
break;
}
p->lx += p->vx;
p->ly += p->vy;
// p->x = p->ox + p->lx;
// p->y = p->oy + p->ly;
p->x = p->ox + floor(fabs(p->lx))*(p->lx/fabs(p->lx));
p->y = p->oy + floor(fabs(p->ly))*(p->ly/fabs(p->ly));
p->x += (128 + 16); /* 表示用に補正 */
p->y += (128 + 16);
xsp_set_st (p);
fxsp_set_st (p);
p->x -= (128 + 16);
p->y -= (128 + 16);
break;
case 8: /* 可動部(右上) */
case 9:
case 10:
case 11:
switch (p->cyc) {
case 0:
p->vx += P_A;
if (p->vx > P_MAXV)
p->vx = P_MAXV;
p->vy -= P_A;
if (p->vy < -P_MAXV)
p->vy = -P_MAXV;
if (p->lx > 0)
p->cyc++;
break;
case 1:
/* ばね運動 */
p->vx -= p->lx * P_K;
p->vy -= p->ly * P_K;
/* 摩擦 */
if (p->vx > 0)
p->vx -= P_M;
else
p->vx += P_M;
if (p->vy > 0)
p->vy -= P_M;
else
p->vy += P_M;
break;
}
p->lx += p->vx;
p->ly += p->vy;
// p->x = p->ox + p->lx;
// p->y = p->oy + p->ly;
p->x = p->ox + floor(fabs(p->lx))*(p->lx/fabs(p->lx));
p->y = p->oy + floor(fabs(p->ly))*(p->ly/fabs(p->ly));
p->x += (128 + 16); /* 表示用に補正 */
p->y += (128 + 16);
xsp_set_st (p);
fxsp_set_st (p);
p->x -= (128 + 16);
p->y -= (128 + 16);
break;
case 12: /* 可動部(左下) */
case 13:
case 14:
case 15:
switch (p->cyc) {
case 0:
p->vx -= P_A;
if (p->vx < -P_MAXV)
p->vx = -P_MAXV;
p->vy += P_A;
if (p->vy > P_MAXV)
p->vy = P_MAXV;
if (p->lx < 0)
p->cyc++;
break;
case 1:
/* ばね運動 */
p->vx -= p->lx * P_K;
p->vy -= p->ly * P_K;
/* 摩擦 */
if (p->vx > 0)
p->vx -= P_M;
else
p->vx += P_M;
if (p->vy > 0)
p->vy -= P_M;
else
p->vy += P_M;
break;
}
p->lx += p->vx;
p->ly += p->vy;
// p->x = p->ox + p->lx;
// p->y = p->oy + p->ly;
p->x = p->ox + floor(fabs(p->lx))*(p->lx/fabs(p->lx));
p->y = p->oy + floor(fabs(p->ly))*(p->ly/fabs(p->ly));
p->x += (128 + 16); /* 表示用に補正 */
p->y += (128 + 16);
xsp_set_st (p);
fxsp_set_st (p);
p->x -= (128 + 16);
p->y -= (128 + 16);
break;
case 16: /* 可動部(右下) */
case 17:
case 18:
case 19:
switch (p->cyc) {
case 0:
p->vx += P_A;
if (p->vx > P_MAXV)
p->vx = P_MAXV;
p->vy += P_A;
if (p->vy > P_MAXV)
p->vy = P_MAXV;
if (p->lx > 0)
p->cyc++;
break;
case 1:
/* ばね運動 */
p->vx -= p->lx * P_K;
p->vy -= p->ly * P_K;
/* 摩擦 */
if (p->vx > 0)
p->vx -= P_M;
else
p->vx += P_M;
if (p->vy > 0)
p->vy -= P_M;
else
p->vy += P_M;
break;
}
p->lx += p->vx;
p->ly += p->vy;
// p->x = p->ox + p->lx;
// p->y = p->oy + p->ly;
p->x = p->ox + floor(fabs(p->lx))*(p->lx/fabs(p->lx));
p->y = p->oy + floor(fabs(p->ly))*(p->ly/fabs(p->ly));
p->x += (128 + 16); /* 表示用に補正 */
p->y += (128 + 16);
xsp_set_st (p);
fxsp_set_st (p);
p->x -= (128 + 16);
p->y -= (128 + 16);
break;
default:
break;
}
if (erase_flag) {
if (q == NULL) { /* リストの一番最初を削除 */
enemy_top = p->next;
p->next = enemy_null_top;
enemy_null_top = p;
q = NULL;
p = enemy_top;
} else {
q->next = p->next;
p->next = enemy_null_top;
enemy_null_top = p;
p = q->next;
}
} else {
q = p;
p = p->next;
}
}
}
void enemy_tini (void)
{
int i;
enemy_top = NULL;
enemy_null_top = enemy;
for (i = 0; i < enemy_MAX; i++) {
enemy[i].next = &enemy[i + 1];
}
enemy[enemy_MAX - 1].next = NULL;
}